package com.wdcg.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wdcg.R;
import com.wdcg.model.access.BonusAccess;
import com.wdcg.model.dao.BonusDescription;
import com.wdcg.model.dao.BonusTypeDescription;

/**
 * @author Grzegorz Matyszczak<BR>
 *
 */
public class BonusInfoFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View v = inflater.inflate(R.layout.fragment_bonus_info, container, false);
		return v;
	}
	
	@Override
	public void onResume() {
		super.onResume();
		Bundle bundle = getArguments();
		int bonusDescrId = bundle.getInt(getString(R.string.bundle_bonus_descr_id));
		BonusDescription bonus = BonusAccess.getBonusDescriptionById(bonusDescrId);
		BonusTypeDescription bonusType = BonusAccess.getBonusTypeDescriptionForBonusDescription(bonus);
		
        getActivity().getActionBar().setTitle(bonus.getName());
		
		ImageView bonusImageView = (ImageView) getActivity().findViewById(R.id.bonusInfoImageView);
		TextView bonusDescrTextView = (TextView) getActivity().findViewById(R.id.bonusDescriptionTextView);
		TextView bonusTypeNameTextView = (TextView) getActivity().findViewById(R.id.bonusTypeNameTextView);
		TextView bonusTypeDescriptionTextView = (TextView) getActivity().findViewById(R.id.bonusTypeDescriptionTextView);
		
		bonusImageView.setImageResource(getResources().getIdentifier("@drawable/"+bonus.getBonus().getImgTitle(), null, getActivity().getPackageName()));
		bonusDescrTextView.setText(bonus.getDescription());
		bonusTypeNameTextView.setText(bonusType.getName());
		bonusTypeDescriptionTextView.setText(bonusType.getDescription());
		
	}
}
